/*******************************************************************************
 * Copyright (c) 2008 Nels E. Beckman.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Nels E. Beckman - initial API and implementation
 *******************************************************************************/
package edu.cmu.cs.nbeckman.wptranslator;

import java.util.TreeMap;

/**
 * A class meant to keep track of the mappings from WP41 to Java Strings.
 * 
 * @author Nels E. Beckman
 */
public class CharacterEncoding {

	private static final TreeMap<Byte,String> charMap = new TreeMap<Byte,String>();
	
	static {
		// 48-57 are the digits
		for(byte i=48;i<=57;i++) {
			int digit = 0;
			charMap.put(i, String.valueOf(digit));
		}
		
		// 65-90 are the uppercase letters
		charMap.put((byte)65, "A");
		charMap.put((byte)66, "B");
		charMap.put((byte)67, "C");
		charMap.put((byte)68, "D");
		charMap.put((byte)69, "E");
		charMap.put((byte)70, "F");
		charMap.put((byte)71, "G");
		charMap.put((byte)72, "H");
		charMap.put((byte)73, "I");
		charMap.put((byte)74, "J");
		charMap.put((byte)75, "K");
		charMap.put((byte)76, "L");
		charMap.put((byte)77, "M");
		charMap.put((byte)78, "N");
		charMap.put((byte)79, "O");
		charMap.put((byte)80, "P");
		charMap.put((byte)81, "Q");
		charMap.put((byte)82, "R");
		charMap.put((byte)83, "S");
		charMap.put((byte)84, "T");
		charMap.put((byte)85, "U");
		charMap.put((byte)86, "V");
		charMap.put((byte)87, "W");
		charMap.put((byte)88, "X");
		charMap.put((byte)89, "Y");
		charMap.put((byte)90, "Z");
		
		// 97-122 are the lowercase letters
		charMap.put((byte)97, "a");
		charMap.put((byte)98, "b");
		charMap.put((byte)99, "c");
		charMap.put((byte)100, "d");
		charMap.put((byte)101, "e");
		charMap.put((byte)102, "f");
		charMap.put((byte)103, "g");
		charMap.put((byte)104, "h");
		charMap.put((byte)105, "i");
		charMap.put((byte)106, "j");
		charMap.put((byte)107, "k");
		charMap.put((byte)108, "l");
		charMap.put((byte)109, "m");
		charMap.put((byte)110, "n");
		charMap.put((byte)111, "o");
		charMap.put((byte)112, "p");
		charMap.put((byte)113, "q");
		charMap.put((byte)114, "r");
		charMap.put((byte)115, "s");
		charMap.put((byte)116, "t");
		charMap.put((byte)117, "u");
		charMap.put((byte)118, "v");
		charMap.put((byte)119, "w");
		charMap.put((byte)120, "x");
		charMap.put((byte)121, "y");
		charMap.put((byte)122, "z");
	}
	
	/**
	 * Does the given b
	 */
	public static boolean isText(byte b) {
		return charMap.containsKey(b);
	}
	
	/**
	 * Return the string that this byte represents.
	 */
	public static String getText(byte b) {
		if( charMap.containsKey(b) )
			return charMap.get(b);
		else
			throw new RuntimeException();
	}
}
